//
//  RegisterController.m
//  20240823
//
//  Created by 张伟 on 2024/8/27.
//

#import "RegisterController.h"

@interface RegisterController ()
@property (weak, nonatomic) IBOutlet UITextField *account;
@property (weak, nonatomic) IBOutlet UITextField *pwd1;
@property (weak, nonatomic) IBOutlet UITextField *pwd2;
@property (nonatomic) BOOL canRegister;
@end

@implementation RegisterController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

-(void)setupUI {
    
}

- (IBAction)registerAndLogin:(UIButton *)sender {

    if (!self.canRegister) {
        return;
    }
    
    MJWeakSelf
    [NetService requestRegister:_account.text password:_pwd1.text successHandle:^{
        [ZWHud showMessage:@"登录成功" finishHandle:nil];
        //其他也许逻辑
        [weakSelf back];
    } fail:^{
        
    }];

}

-(void)back{
    //找到模态控制器
    UIViewController *presentingViewController = self.presentingViewController;
    while (presentingViewController.presentingViewController) {
        presentingViewController = presentingViewController.presentingViewController;
    }
    [presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)canRegister {
    
    if (_account.text.length == 0) {
        [ZWHud showMessage:@"账号不能为空" finishHandle:nil];
        return false;
    }
    
    if (_pwd1.text.length == 0 || _pwd2.text.length == 0) {
        [ZWHud showMessage:@"密码不能为空" finishHandle:nil];
        return false;
    }
    
    if (![_pwd1.text isEqualToString:_pwd2.text]) {
        [ZWHud showMessage:@"两次密码不一致" finishHandle:nil];
        return false;
    }
    
    return true;
}


@end
